package com.example.demo.controller;

import com.example.demo.entity.User;
import com.example.demo.service.SchedualServerHi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * Created by wangjialei on 2018/10/9.
 */
@RestController
public class HiController {

    //编译器报错，无视。 因为这个Bean是在程序启动的时候注入的，编译器感知不到，所以报错。
    @Autowired
    SchedualServerHi schdualServerHi;


    @Value("${server.port}")
    String port;





    @GetMapping(value = "/hi")
    public String sayHi(@RequestParam String name) {
        return schdualServerHi.sayHiFromClientOne( name );
    }



    //测试接口压力-不使用redis缓存
    @RequestMapping("/test1")
    public List<User> interfac(){

        List<User> users = schdualServerHi.getAllUser();

        return users;
    }

    //测试接口压力-使用redis缓存
    @RequestMapping("/test2")
    public List<User> interfaceRedis(){

        List<User> users = schdualServerHi.getAllUserRedis();

        return users;
    }


    //获取服务提供方(server-hi的两个实例)的session以检测session是否一致
    @GetMapping(value = "/get")
    public String get() {
        String result = "port"+port+",feign get remote session :"+ schdualServerHi.get();
        System.out.println(result);
        return result;
    }



}
